package com.nine.gxh.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nine.gxh.mapper.GxhInfoChannelLogMapper;
import com.nine.gxh.model.GxhInfoChannelLog;
import com.nine.gxh.service.GxhInfoChannelLogService;
import com.ruoyi.common.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author: duonine
 * @date: 2023/7/4
 */
@Service
@Slf4j
public class GxhInfoChannelLogServiceImpl extends ServiceImpl<GxhInfoChannelLogMapper, GxhInfoChannelLog> implements GxhInfoChannelLogService {

    @Async
    @Override
    public void saveChannelLog() {
        log.info("测试异步功能【异步方法】。。。。。。。。。。。。。。。。。");
    }

    @Override
    public void saveChannelLog(Long cid, String operatetype) {
        log.info("cid::::{}", cid);

        GxhInfoChannelLog channelLog = new GxhInfoChannelLog();
        channelLog.setCid(cid);
        channelLog.setOperatetime(new Date());
        // 其他
        channelLog.setOperatetype(operatetype);

        // 此处需要人员必须登录才能访问
        if (SecurityUtils.getUserId() != null) {
            channelLog.setOperateuserid(SecurityUtils.getUserId());
            channelLog.setOperateusername(SecurityUtils.getUsername());
        }
        else {
            channelLog.setOperateuserid(1L);
            channelLog.setOperateusername("admin");
        }
        this.save(channelLog);
    }

}
